# $Id: PKGBUILD 180687 2013-03-25 19:15:38Z bpiotrowski $
# Contributor: Jeff Brodnax <tullyarcher@bellsouth.net>
# Contributor: Paul Mattal <paul@archlinux.org>
# Maintainer: Gaetan Bisson <bisson@archlinux.org>

pkgname=postfix
pkgver=2.10.0
pkgrel=4
pkgdesc='Fast, easy to administer, secure mail server'
url='http://www.postfix.org/'
license=('custom')
arch=('i686' 'x86_64')
depends=('pcre' 'libsasl' 'libldap' 'db'
         'libmariadbclient' 'postgresql-libs' 'sqlite' 'tinycdb')
backup=('etc/postfix/'{access,aliases,canonical,generic,header_checks,main.cf,master.cf,relocated,transport,virtual})
source=("ftp://ftp.porcupine.org/mirrors/postfix-release/official/${pkgname}-${pkgver}.tar.gz"
        'aliases.patch'
        'service'
        'rc.d')
sha1sums=('dd9bfc7afee416aa9f2368d084a4b202718e42df'
          '5fc3de6c7df1e5851a0a379e825148868808318b'
          '3f385eca6d571a4ed8fb24781bdc003bec5d8ed6'
          '40c6be2eb55e6437a402f43775cdb3d22ea87a66')

provides=('smtp-server' 'smtp-forwarder')
conflicts=('smtp-server' 'smtp-forwarder')

install=install

build() {
	cd "${srcdir}/${pkgname}-${pkgver}"

	make makefiles DEBUG='' CCARGS=' \
		-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl \
		-DHAS_LDAP \
		-DUSE_TLS \
		-DHAS_MYSQL -I/usr/include/mysql \
		-DHAS_PGSQL -I/usr/include/postgresql \
		-DHAS_SQLITE \
		-DHAS_CDB \
		-DDEF_MANPAGE_DIR=\"/usr/share/man\" \
		-DDEF_DAEMON_DIR=\"/usr/lib/postfix\" \
		-DDEF_SAMPLE_DIR=\"/etc/postfix/sample\" \
		-DDEF_README_DIR=\"/usr/share/doc/postfix\" \
	' AUXLIBS=' \
		-lsasl2 \
		-lldap -llber \
		-lssl -lcrypto \
		-lmysqlclient -lz -lm \
		-lpq \
		-lsqlite3 -lpthread \
		-lcdb \
	' OPT="${CFLAGS} ${LDFLAGS}"

	make
}

package() {
	cd "${srcdir}/${pkgname}-${pkgver}"

	sh postfix-install -non-interactive install_root="${pkgdir}"

	install -Dm755 ../rc.d "${pkgdir}/etc/rc.d/${pkgname}"
	install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
	install -Dm644 ../service "${pkgdir}/usr/lib/systemd/system/${pkgname}.service"

	cd "${pkgdir}"
	patch -p0 -i "${srcdir}"/aliases.patch
	sed 's/^\(\$manpage[^:]*\):/\1.gz:/' -i "usr/lib/${pkgname}/postfix-files"
}
